{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Title: #Remove Trailing Zeros From a String"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Difficulty: #Easy"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Category Title: #Algorithms"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Tag Slug: #string"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Name Translated: #字符串"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Solution Name: removeTrailingZeros"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Translated Title: #移除字符串中的尾随零"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Translated Content:\n",
    "<p>给你一个用字符串表示的正整数 <code>num</code> ，请你以字符串形式返回不含尾随零的整数<em> </em><code>num</code><em> </em>。</p>\n",
    "\n",
    "<p>&nbsp;</p>\n",
    "\n",
    "<p><strong>示例 1：</strong></p>\n",
    "\n",
    "<pre><strong>输入：</strong>num = \"51230100\"\n",
    "<strong>输出：</strong>\"512301\"\n",
    "<strong>解释：</strong>整数 \"51230100\" 有 2 个尾随零，移除并返回整数 \"512301\" 。\n",
    "</pre>\n",
    "\n",
    "<p><strong>示例 2：</strong></p>\n",
    "\n",
    "<pre><strong>输入：</strong>num = \"123\"\n",
    "<strong>输出：</strong>\"123\"\n",
    "<strong>解释：</strong>整数 \"123\" 不含尾随零，返回整数 \"123\" 。\n",
    "</pre>\n",
    "\n",
    "<p>&nbsp;</p>\n",
    "\n",
    "<p><strong>提示：</strong></p>\n",
    "\n",
    "<ul>\n",
    "\t<li><code>1 &lt;= num.length &lt;= 1000</code></li>\n",
    "\t<li><code>num</code> 仅由数字 <code>0</code> 到 <code>9</code> 组成</li>\n",
    "\t<li><code>num</code> 不含前导零</li>\n",
    "</ul>\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Description: [remove-trailing-zeros-from-a-string](https://leetcode.cn/problems/remove-trailing-zeros-from-a-string/description/)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Solutions: [remove-trailing-zeros-from-a-string](https://leetcode.cn/problems/remove-trailing-zeros-from-a-string/solutions/)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "test_cases = ['\"51230100\"', '\"123\"']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def removeTrailingZeros(self, num: str) -> str:\n",
    "        while num[-1] == '0':\n",
    "            num = num.strip('0')\n",
    "        return num"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def removeTrailingZeros(self, num: str) -> str:\n",
    "        return num.rstrip('0')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def removeTrailingZeros(self, num: str) -> str:\n",
    "        return num.rstrip('0')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def removeTrailingZeros(self, num: str) -> str:\n",
    "        return num.rstrip('0')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def removeTrailingZeros(self, num: str) -> str:\n",
    "    \n",
    "        return num.rstrip('0')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def removeTrailingZeros(self, num: str) -> str:\n",
    "        return num.rstrip('0')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def removeTrailingZeros(self, num: str) -> str:\n",
    "        for i in num[::-1]:\n",
    "            if i !='0':\n",
    "                return num[:len(num)-(num[::-1].index(str(i)))]\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def removeTrailingZeros(self, num: str) -> str:\n",
    "        num = int(num)\n",
    "        while num % 10 == 0:\n",
    "            num //= 10\n",
    "        return str(num)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def removeTrailingZeros(self, num: str) -> str:\n",
    "        index=len(num)-1\n",
    "        while num[index]==\"0\":\n",
    "            index-=1\n",
    "        return num[:index+1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def removeTrailingZeros(self, num: str) -> str:\n",
    "        return num.rstrip(\"0\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def removeTrailingZeros(self, num: str) -> str:\n",
    "        k = 0\n",
    "        for n in num[::-1]:\n",
    "            if n == \"0\":\n",
    "                k += 1\n",
    "            else:\n",
    "                break\n",
    "        if k == 0:\n",
    "            return num\n",
    "        return num[:-k]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def removeTrailingZeros(self, num: str) -> str:\n",
    "        return num.strip('0')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def removeTrailingZeros(self, num: str) -> str:\n",
    "        return num.rstrip('0')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def removeTrailingZeros(self, num: str) -> str:\n",
    "        while True:\n",
    "            if num[-1] != \"0\":\n",
    "                break\n",
    "            num = num[:-1]\n",
    "        return num\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def removeTrailingZeros(self, num: str) -> str:\n",
    "        return num.rstrip('0')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def removeTrailingZeros(self, num: str) -> str:\n",
    "        return num.rstrip('0')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def removeTrailingZeros(self, num: str) -> str:\n",
    "        t=len(num)\n",
    "        list_s=list(num)\n",
    "        for i in list_s[::-1]:\n",
    "            if i=='0':\n",
    "                t-=1\n",
    "            else:\n",
    "                break\n",
    "        \n",
    "             \n",
    "        return \"\".join(list_s)[0:t]  "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "# @Author: fankang\n",
    "# @Time: 2023/11/16 21:32\n",
    "class Solution:\n",
    "    def removeTrailingZeros(self, num: str) -> str:\n",
    "        ll = list(num)\n",
    "        ll.reverse()\n",
    "        f = 0\n",
    "        for i in ll:\n",
    "            if i != '0':\n",
    "                f = ll.index(i)\n",
    "                break\n",
    "        ll = ll[f:]\n",
    "        ll.reverse()\n",
    "        return ''.join(ll)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def removeTrailingZeros(self, num: str) -> str:\n",
    "        num = int(num)\n",
    "        while not num % 10:\n",
    "            num //= 10\n",
    "        return str(num)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def removeTrailingZeros(self, num: str) -> str:\n",
    "        leng = len(num) - 1\n",
    "        ans = num\n",
    "        while  leng >= 0:\n",
    "            if num[leng] == '0':\n",
    "                leng = leng - 1\n",
    "            else:\n",
    "                ans = num[0:leng+1]\n",
    "                break\n",
    "        return ans\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def removeTrailingZeros(self, num: str) -> str:\n",
    "        return num.strip(\"0\")\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def removeTrailingZeros(self, num: str) -> str:\n",
    "        res = num.strip(\"0\")\n",
    "        return res"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def removeTrailingZeros(self, num: str) -> str:\n",
    "        while num[-1]=='0':\n",
    "            num=num[:-1]\n",
    "        return num"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def removeTrailingZeros(self, num: str) -> str:\n",
    "        return num.strip('0')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def removeTrailingZeros(self, num: str) -> str:\n",
    "        return num.strip(\"0\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def removeTrailingZeros(self, num: str) -> str:\n",
    "        return num.rstrip('0')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def removeTrailingZeros(self, num: str) -> str:\n",
    "        return num.rstrip('0')\n",
    "        # nums = list(num)\n",
    "        # for i in range(len(nums)):\n",
    "        #     if nums[-1] == \"0\":\n",
    "        #         nums.pop()\n",
    "        # return ''.join(nums)    "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def removeTrailingZeros(self, num: str) -> str:\n",
    "        while num[-1] == \"0\":\n",
    "            num=num[:-1]\n",
    "        return num"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def removeTrailingZeros(self, num: str) -> str:\n",
    "        while len(num)>0 and num[-1]=='0':\n",
    "            num = num[:-1]\n",
    "        return num"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def removeTrailingZeros(self, num: str) -> str:\n",
    "        return num.rstrip(\"0\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def removeTrailingZeros(self, num: str) -> str:\n",
    "        idx = len(num) - 1\n",
    "        while num[idx] == '0':\n",
    "            idx -= 1\n",
    "        return num[:idx+1]\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def removeTrailingZeros(self, num: str) -> str:\n",
    "        for i in range(len(num)-1, -1, -1):\n",
    "            if num[i] == '0':\n",
    "                num = num[:i]\n",
    "            else:\n",
    "                break\n",
    "        return num\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def removeTrailingZeros(self, num: str) -> str:\n",
    "        return num.rstrip('0')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def removeTrailingZeros(self, num: str) -> str:\n",
    "        while num[-1] == '0':\n",
    "             num = num[:-1]\n",
    "        return num"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def removeTrailingZeros(self, num: str) -> str:\n",
    "        while int(num)%10==0:\n",
    "            num = num[:-1]\n",
    "        return num"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def removeTrailingZeros(self, num: str) -> str:\n",
    "        return num.rstrip('0')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def removeTrailingZeros(self, num: str) -> str:\n",
    "        num = num[::-1]\n",
    "        count = 0\n",
    "        for i in range(0,len(num)):\n",
    "            if num[i] == \"0\":\n",
    "                count += 1\n",
    "            else:\n",
    "                break\n",
    "        num = num[count:][::-1]\n",
    "        return num"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def removeTrailingZeros(self, num: str) -> str:\n",
    "        n=len(num)-1\n",
    "        while num[n]=='0':\n",
    "            n=n-1\n",
    "        return num[0:n+1]\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def removeTrailingZeros(self, num: str) -> str:\n",
    "        for i in range(len(num)-1,-1,-1):\n",
    "            if num[i] !='0':\n",
    "                break\n",
    "        return num[:i+1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def removeTrailingZeros(self, num: str) -> str:\n",
    "        j = len(num) -1\n",
    "        while j >= 0:\n",
    "            if num[j] == '0':\n",
    "                j -= 1\n",
    "            else:\n",
    "                return num[:j+1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def removeTrailingZeros(self, num: str) -> str:\n",
    "        i = len(num) - 1\n",
    "        while num[i] == \"0\":\n",
    "            i -= 1\n",
    "        return num[:i + 1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def removeTrailingZeros(self, num: str) -> str:\n",
    "        return num.rstrip('0')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def removeTrailingZeros(self, num: str) -> str:\n",
    "        return num.rstrip(\"0\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def removeTrailingZeros(self, num: str) -> str:\n",
    "        n = -1\n",
    "        while num[n] == \"0\":\n",
    "            n = n - 1\n",
    "        if n == -1:\n",
    "            return num\n",
    "        else:\n",
    "            return num[:n+1]\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def removeTrailingZeros(self, num: str) -> str:\n",
    "        if num[-1] != '0':\n",
    "            return num\n",
    "        n = len(num) - 1\n",
    "        while num[n] == '0':\n",
    "            n -= 1\n",
    "        return num[:n + 1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def removeTrailingZeros(self, num: str) -> str:\n",
    "        return num.rstrip('0')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def removeTrailingZeros(self, nums: str) -> str:\n",
    "        while nums[-1] == '0':\n",
    "            nums = nums[:-1]\n",
    "        return nums if nums else '0'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def removeTrailingZeros(self, num: str) -> str:\n",
    "        # leng = len(num) - 1\n",
    "        # ans = num\n",
    "        # while  leng >= 0:\n",
    "        #     if num[leng] == '0':\n",
    "        #         leng = leng - 1\n",
    "        #     else:\n",
    "        #         ans = num[0:leng+1]\n",
    "        #         break\n",
    "        # return ans\n",
    "\n",
    "        ans = num[::-1]\n",
    "        i = int(ans)\n",
    "        return str(i)[::-1]\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def removeTrailingZeros(self, num: str) -> str:\n",
    "        return num.strip('0')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def removeTrailingZeros(self, num: str) -> str:\n",
    "        nums_l=num[::-1]\n",
    "        print(nums_l)\n",
    "        count=0\n",
    "        for i in nums_l:\n",
    "            if i==\"0\":\n",
    "                count+=1\n",
    "            else:\n",
    "                break\n",
    "        return num[:len(num)-count]\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def removeTrailingZeros(self, num: str) -> str:\n",
    "        # cnt = 0\n",
    "        # for i in range(len(num)-1, -1, -1):\n",
    "        #     if num[i] == '0':\n",
    "        #         cnt += 1\n",
    "        #     else:\n",
    "        #         break\n",
    "        # return num[:len(num) - cnt]\n",
    "        return num.rstrip('0')\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def removeTrailingZeros(self, num: str) -> str:\n",
    "        right_fast = len(num) - 1\n",
    "\n",
    "        while right_fast > 0:\n",
    "            if int(num[right_fast]) == 0:\n",
    "                right_fast -= 1\n",
    "            else:\n",
    "                break\n",
    "                \n",
    "        \n",
    "        return num[:right_fast+1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def removeTrailingZeros(self, num: str) -> str:\n",
    "        return str(int(num[::-1]))[::-1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def removeTrailingZeros(self, num: str) -> str:\n",
    "        n = len(num)\n",
    "        j = n - 1\n",
    "        while j >= 1:\n",
    "            if num[j] != '0':\n",
    "                break\n",
    "            j -= 1\n",
    "        return num[:(j+1)]\n",
    "            "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def removeTrailingZeros(self, num: str) -> str:\n",
    "        data = int(num)\n",
    "        while data % 10 == 0:\n",
    "            data //= 10\n",
    "        return str(data)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def removeTrailingZeros(self, num: str) -> str:\n",
    "        return num.rstrip('0')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def removeTrailingZeros(self, num: str) -> str:\n",
    "        n=len(num)\n",
    "        \n",
    "        for i in range(n-1,-1,-1):\n",
    "            if num[i]==\"0\":\n",
    "                pass\n",
    "\n",
    "            else:\n",
    "                cnt=i\n",
    "                break\n",
    "            \n",
    "        return num[:cnt+1]\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def removeTrailingZeros(self, num: str) -> str:\n",
    "        return num.rstrip('0')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def removeTrailingZeros(self, num: str) -> str:\n",
    "        for i in range(len(num)-1,-1,-1):\n",
    "            print(num[i])\n",
    "            if num[i]=='0':\n",
    "                num=num[0:i]\n",
    "            else:\n",
    "                return num"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def removeTrailingZeros(self, num: str) -> str:\n",
    "         return num.rstrip('0')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def removeTrailingZeros(self, num: str) -> str:\n",
    "        s=list(num)\n",
    "        for i in range(len(s)-1,-1,-1):\n",
    "            if s[i]==\"0\":\n",
    "                del s[i]\n",
    "            else:\n",
    "                break\n",
    "        n=\"\"\n",
    "        for k in s:\n",
    "            n+=k\n",
    "        return n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def removeTrailingZeros(self, num: str) -> str:\n",
    "        cnt = 0\n",
    "        for i in range(len(num)-1, -1, -1):\n",
    "            if num[i] == '0':\n",
    "                cnt += 1\n",
    "            else:\n",
    "                break\n",
    "        return num[:len(num) - cnt]\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def removeTrailingZeros(self, num: str) -> str:\n",
    "        # while num[-1]==\"0\":\n",
    "        #     num = num[:-1]\n",
    "        # return num\n",
    "        i = len(num)\n",
    "        while i>=0 and num[i-1]=='0':\n",
    "            i-=1\n",
    "        return num[:i] "
   ]
  }
 ],
 "metadata": {},
 "nbformat": 4,
 "nbformat_minor": 2
}
